package com.mp.approvalreq.servlet.component;

import com.mp.approvalreq.entity.dto.ComponentGroupDTO;
import com.mp.approvalreq.entity.vo.ComponentGroupVO;
import com.mp.approvalreq.service.SelectApprovalServicePrx;
import com.mp.approvalreq.servlet.AbstractServlet;
import com.mp.approvalreq.util.ServiceUtils;
import com.mp.user.entity.User;
import com.plusmoney.message.SuccessMsg;
import com.plusmoney.util.BeanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 *
 * @author liuqi
 * @date 2018/9/18
 */
@WebServlet("/getComponentGroupList")
public class GetComponentGroupList extends AbstractServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		try {
			User user = getReqUser(req);
			
			SelectApprovalServicePrx selectApprovalService = ServiceUtils.getSelectApprovalServicePrx();
			
			List<ComponentGroupDTO> componentGroupDTOs = selectApprovalService.getComponentGroupDTOs(user.getCompanyId());
			
			List<ComponentGroupVO> componentGroupVOs = BeanUtils.dtos2pos(componentGroupDTOs, ComponentGroupVO.class);
			
			printJson(resp, SuccessMsg.getDefaultMsg(componentGroupVOs));
		} catch (Throwable e) {
			onThrowable(req, resp, e);
		}
	}
	
}
